package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qianfeng.lingshijia.R;

import java.util.ArrayList;
import java.util.List;


/**
 * 详情界面规格参数适配器
 */
public class DetailTypeAdapater extends BaseAdapter{


    private List<String> data;
    private Context context;

    public DetailTypeAdapater(Context context)
    {
        this.context = context;
        data = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setData(List<String> data) {
        this.data = data;

        notifyDataSetChanged();
    }

    private String title;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.detail_type_item,null);
            vh = new ViewHolder();
            vh.textView = (TextView)convertView.findViewById(R.id.id_tv_detailtype);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        title = data.get(position);
        vh.textView.setText(title);
        return convertView;
    }

    class ViewHolder
    {
        TextView textView;
    }
}
